package com.carl.web.demo;

import com.alibaba.fastjson.JSON;
import com.carl.pojo.Brand;
import com.carl.service.BrandService;
import com.carl.service.impl.BrandServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet(name = "addBrandServlet", value = "/addBrandServlet")
public class AddBrandServlet extends HttpServlet {
    private BrandService brandService = new BrandServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("addDoGet");

        BufferedReader reader = request.getReader();
        String params = reader.readLine();
        System.out.println(params);
        Brand brand = JSON.parseObject(params, Brand.class);

        brandService.add(brand);

        response.getWriter().write("success");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("addDoPOST");

        this.doGet(request, response);
    }
}
